#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
作者: jena
创建时间: 2025.9
配置类模块
提供各种处理器的配置类，简化参数传递
"""

from typing import List, Optional
from dataclasses import dataclass


@dataclass
class CharacterCleanerConfig:
    """
    字符处理器配置类
    替代复杂的参数列表，提供清晰的配置接口
    按功能执行顺序排列参数
    """
    # ========== 文本标准化处理 ==========
    # 1. 去除不可见字符
    enable_invisible_chars_removal: bool = False
    # 2. Unicode标准化
    enable_unicode_normalize: bool = False
    # 3. 繁体转简体
    enable_traditional_convert: bool = False
    
    # ========== 内容格式清理 ==========
    # 4. 去除HTML标签
    enable_html_removal: bool = False
    # 5. 去除Markdown格式
    enable_markdown_removal: bool = False
    # 6. 删除装饰符号
    enable_decorative_symbols_removal: bool = False
    
    # ========== 个人隐私信息打码 ==========
    # 7. 个人信息打码
    enable_personal_info_masking: bool = False
    # 8. 银行卡号打码
    enable_bank_card_masking: bool = False
    
    # ========== 网络隐私信息打码 ==========
    # 9. 网络标识符打码
    enable_network_identifiers_masking: bool = False
    # 10. 网络凭证打码
    enable_network_credentials_masking: bool = False
    
    # ========== 标点符号标准化 ==========
    # 11. 标点符号转换
    enable_punctuation_normalize: bool = False
    
    # ========== 空白字符删除 ==========
    # 12. 删除空白字符
    enable_whitespace_removal: bool = False
    
    def to_dict(self) -> dict:
        """转换为字典格式，便于传递给处理方法（按功能执行顺序排列）"""
        return {
            # ========== 文本标准化处理 ==========
            'enable_invisible_chars_removal': self.enable_invisible_chars_removal,
            'enable_unicode_normalize': self.enable_unicode_normalize,
            'enable_traditional_convert': self.enable_traditional_convert,
            # ========== 内容格式清理 ==========
            'enable_html_removal': self.enable_html_removal,
            'enable_markdown_removal': self.enable_markdown_removal,
            'enable_decorative_symbols_removal': self.enable_decorative_symbols_removal,
            # ========== 个人隐私信息打码 ==========
            'enable_personal_info_masking': self.enable_personal_info_masking,
            'enable_bank_card_masking': self.enable_bank_card_masking,
            # ========== 网络隐私信息打码 ==========
            'enable_network_identifiers_masking': self.enable_network_identifiers_masking,
            'enable_network_credentials_masking': self.enable_network_credentials_masking,
            # ========== 标点符号标准化 ==========
            'enable_punctuation_normalize': self.enable_punctuation_normalize,
            # ========== 空白字符删除 ==========
            'enable_whitespace_removal': self.enable_whitespace_removal
        }


@dataclass
class SentenceCleanerConfig:
    """
    句子清理器配置类
    用于配置句子级别的清理和筛选功能
    """
    # MD5去重功能
    enable_md5_dedup: bool = False
    # jieba重复度过滤功能
    enable_jieba_filter: bool = False
    # n-gram相似度过滤功能
    enable_ngram_filter: bool = False
    # 字段内容过滤功能
    enable_field_filter: bool = False
    # 文本长度过滤功能
    enable_length_filter: bool = False
    # 关键词过滤功能
    enable_keyword_filter: bool = False
    
    # jieba重复度过滤参数
    repetition_threshold: float = 0.5
    jieba_cut_all: bool = False
    
    # n-gram相似度过滤参数
    ngram_similarity_threshold: float = 0.8
    ngram_n: int = 2
    
    # 字段过滤参数
    target_fields: Optional[List[str]] = None
    field_filter_mode: str = 'include'  # 'include' or 'exclude'
    field_match_mode: str = 'any'  # 'any' or 'all'
    field_case_sensitive: bool = False
    field_use_jieba: bool = False
    
    # 长度过滤参数
    min_length: int = 1
    max_length: int = 1000
    length_count_mode: str = 'char'  # 'char' 或 'word'
    
    def to_dict(self) -> dict:
        """转换为字典格式，便于传递给处理方法"""
        return {
            'enable_md5_dedup': self.enable_md5_dedup,
            'enable_jieba_filter': self.enable_jieba_filter,
            'enable_ngram_filter': self.enable_ngram_filter,
            'enable_field_filter': self.enable_field_filter,
            'enable_length_filter': self.enable_length_filter,
            'repetition_threshold': self.repetition_threshold,
            'jieba_cut_all': self.jieba_cut_all,
            'ngram_similarity_threshold': self.ngram_similarity_threshold,
            'ngram_n': self.ngram_n,
            'target_fields': self.target_fields,
            'field_filter_mode': self.field_filter_mode,
            'field_match_mode': self.field_match_mode,
            'field_case_sensitive': self.field_case_sensitive,
            'field_use_jieba': self.field_use_jieba,
            'min_length': self.min_length,
            'max_length': self.max_length,
            'length_count_mode': self.length_count_mode
        }

